package eu.news.kits;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class TimeString {
	
	public static String getTimeNumberString(int length){
		NumberFormat format =  new DecimalFormat("00");
		Calendar cal=Calendar.getInstance();
		String timeString=cal.get(Calendar.YEAR)+
			format.format(cal.get(Calendar.MONTH)+1)
			+format.format(cal.get(Calendar.DAY_OF_MONTH))
			+format.format(cal.get(Calendar.HOUR_OF_DAY))
			+format.format(cal.get(Calendar.MINUTE))
			+format.format(cal.get(Calendar.SECOND));
		if(length>timeString.length())
			length=timeString.length();
		return timeString.substring(0, length);
	}
	
	public static String getTimeString(int length){
		NumberFormat format =  new DecimalFormat("00");
		Calendar cal=Calendar.getInstance();
		String timeString=cal.get(Calendar.YEAR)+"-"+
			format.format(cal.get(Calendar.MONTH)+1)+"-"
			+format.format(cal.get(Calendar.DAY_OF_MONTH))+"  "
			+format.format(cal.get(Calendar.HOUR_OF_DAY))+":"
			+format.format(cal.get(Calendar.MINUTE))+":"
			+format.format(cal.get(Calendar.SECOND));
		return timeString.substring(0, length);
	}
	
	public static String getTimeString(Date time,String format){
		SimpleDateFormat simFormat = new SimpleDateFormat(format, Locale.CHINA); 
		return simFormat.format(time); 
	}
}
